package com.logistics.delivery.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;

import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.delivery.entity.model.DeliverySave;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 配送单
 * </p>
 *
 * @author zhiyu.fan
 * @since 2024-06-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lgs_delivery")
public class Delivery implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String code;

    private Integer parent;

    private Integer pick;

    private Integer priority;

    private String agv;

    private String type;

    private Integer status;

    private String startStation;

    private String endStation;

    private Integer reqCode;

    private String agvType;

    private String isContainer;

    private BigDecimal unloadHeight;

    private BigDecimal unloadDownloadHeight;

    private BigDecimal loadHeight;

    private BigDecimal containHeight;

    private String zone;

    private String createOrgCode;

    private String createDepCode;

    private String creator;

    private Date createTime;

    private String updater;

    private Date updateTime;

    public Delivery(){}

    public Delivery(DeliverySave save){
        this.id  = StringUtils.isNotNull(save.getId()) ? Integer.parseInt(save.getId()) : null;
        this.code = save.getCode();
        this.parent = StringUtils.isNotNull(save.getParent()) ? Integer.parseInt(save.getParent()) : null;
        this.pick = StringUtils.isNotNull(save.getPick()) ? Integer.parseInt(save.getPick()) : null;
        this.priority = StringUtils.isNotNull(save.getPriority()) ? Integer.parseInt(save.getPriority()) : null;
        this.agv = save.getAgv();
        this.type = save.getType();
        this.status = StringUtils.isNotNull(save.getStatus()) ? Integer.parseInt(save.getStatus()) : null;
        this.startStation = save.getStartStation();
        this.endStation = save.getEndStation();
        this.agvType = save.getAgvType();
        this.isContainer = save.getIsContainer();
        this.unloadHeight = save.getUnloadHeight();
        this.unloadDownloadHeight = save.getUnloadDownloadHeight();
        this.loadHeight = save.getLoadHeight();
        this.containHeight = save.getContainHeight();
        this.zone = save.getZone();
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.creator = save.getCreator();
        this.createTime = DateUtils.stringToDateFormat(save.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        this.updater = save.getUpdater();
        this.updateTime = DateUtils.stringToDateFormat(save.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }

    public static Delivery build(DeliverySave save){
        return new Delivery(save);
    }

    public static Delivery build(Integer reqCode){
        Delivery delivery = new Delivery();
        delivery.setReqCode(reqCode);
        return delivery;
    }

    public static Delivery build(Integer reqCode, String status){
        Delivery delivery = new Delivery();
        delivery.setReqCode(reqCode);
        delivery.setStatus(Integer.parseInt(status));
        return delivery;
    }
}
